using System;
using System.IO;
using System.Xml;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;

//CID 0268 //2009.04.07 //Begin
namespace InfoJetSoft.Service.Util
{
	public class TestDataObject
	{
		public static bool loadTestDataObject( Form form, DataObject dataObject )
		{
			XmlDocument dataDoc = findTestDataObjectDoc( dataObject.Name );
			if( dataDoc != null )
			{
				HashtableUtil.addSafety( form.DataTable, dataObject.Name, dataDoc );
				return true;
			}
			else
			{
				return false;
			}
		}

		public static XmlDocument findTestDataObjectDoc( string name )
		{
			string testFolder = ConfigUtil.GetSetting( "InfoJetSoft.Service.DataObjectTestFolder" );
			if( testFolder != null )
			{
				string testFile = testFolder + "\\" + name + ".xml";
				FileInfo fileInfo = new FileInfo( testFile );
				if( fileInfo.Exists )
				{
					XmlDocument dataDoc = new XmlDocument();
					dataDoc.Load( fileInfo.FullName );
					if( dataDoc.DocumentElement != null )
					{
						return dataDoc;
					}
				}
			}
			return null;
		}
	}
}
//CID 0268 //2009.04.07 //End